# Maintainer: justforlxz <justforlxz@gmail.com>
pkgname=deepin-api-git
pkgver=5.5.12.r8.ga0dc403
pkgrel=1
sourcename=dde-api
sourcetars=("$sourcename"_"$pkgver".tar.xz vendor.tar.gz)
sourcedir="$sourcename"
useforobs=1
pkgdesc='Golang bindings for dde-daemon'
arch=('x86_64' 'aarch64')
url="https://github.com/linuxdeepin/dde-api"
license=('GPL3')
# alsa-utils: alsactl used in sound-theme-player
# bc: used in adjust-grub-theme
# fontconfig: fc-match used in adjust-grub-theme
# librsvg: rsvg-convert used in adjust-grub-theme
# util-linux: rfkill used in device
depends=('alsa-utils' 'bc' 'fontconfig' 'glib2' 'gdk-pixbuf2' 'gtk3' 'libcanberra-pulse' 'librsvg'
         'libxi' 'libxfixes' 'poppler-glib' 'util-linux' 'xcur2png' 'blur-effect' 'gdk-pixbuf-xlib'
         'libgudev')

makedepends=('git' 'bzr' 'go-pie' 'deepin-gettext-tools-git')
provides=('deepin-api')
conflicts=('deepin-api')
groups=('deepin-git')
install=deepin-api.install
source=("${sourcetars[@]}"
        deepin-api.sysusers)
sha512sums=('SKIP' 'SKIP'
            'e894eb3928af9e244fa78010fdf16c8abb6ce18df114cf05327d02b18774d6ba5b023e4dfa0d07042f4e44a5c6e2ddb55b07f3e0db466a0e6169b52465fdefd6')

prepare() {
  cd $sourcedir
  export GOPATH="$PWD/gobuild:/usr/share/gocode"
  if [[ ! -n "$useforobs" ]];then
    export GOFLAGS="-buildmode=pie -trimpath -modcacherw -mod=readonly"
    go mod tidy
  else
    export GOFLAGS="-buildmode=pie -trimpath -modcacherw -mod=vendor"
    cp -a "$srcdir"/vendor "$srcdir"/"$sourcedir"/vendor
  fi
}

build(){
  cd $sourcedir
  make -j1
}

package() {
  cd $sourcedir
  make DESTDIR="$pkgdir" SYSTEMD_LIB_DIR=/usr/lib install
  install -Dm644 ../deepin-api.sysusers "$pkgdir"/usr/lib/sysusers.d/deepin-api.conf
}
